// pages/restaurant/shop/shopComponent/shopComponent.js
import {list, recommendTagList} from '../../api/recommend'
import {list as tagList} from '../../api/tag';
import util from '../../utils/util'
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
			type: Object,
		  }
  },
lifetimes:{
  attached() {
    var arr = Object.keys(this.data.info.tagids)
    if (arr.length > 0) {
    this.data.tagIds = this.data.info.tagids.split(',')
    console.log(this.data.tagIds)
    for (var i = 0; i < this.data.tagIds.length; i++) {
      this.data.tagIds[i] = parseInt(this.data.tagIds[i])
    }
    this.setData({
      tagIds: this.data.tagIds
    })
    // this.loadTag()
    this.loadRecommendList()
    
    }
  //   this.loadShop()
  }
},
  /**
   * 组件的初始数据
   */
  data: {
    shops: [],
		tagIds: [],
		pageNum:1,
		title:"热门推荐",
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toDetail(e){
      wx.navigateTo({
        url: '/pages/shop/shopDetail/index?shopId='+e.currentTarget.dataset.id+'&mchId='+e.currentTarget.dataset.mchid
      })  
      
    },
    loadSHop(){
      list({
        type:1,
        lng:app.globalData.lng,
        lat:app.globalData.lat
      }).then(res=>{
        res.data.data.forEach(item=>{
          item.distance=util.rateConverter(item.distance)
            item.shopVo.logo=util.thumbnail(item.shopVo.logo,187,187)
            item.shopVo.distance = util.rateConverter(item.shopVo.distance)
        })
        this.data.shops=res.data.data
        this.setData({
          shops:this.data.shops
        })
      })
    },
    loadRecommendList(){
			let _this = this
			recommendTagList({
				tagIds:this.data.tagIds
			}).then(res=>{
				console.info("推荐列表信息---",res.data)
				res.data.data.forEach(item=>{
					let shopInfo =  item.shopVo
					shopInfo.logo = util.thumbnail(item.shopVo.logo,190,190)
					shopInfo.distance = util.rateConverter(item.shopVo.distance)
					// item.score=item.score.toFixed(1)
					shopInfo.score= '5.0'
					shopInfo.images=[]
					for(var i=0;i<item.score;i++){
						shopInfo.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/ic_list_star_red%402x.png')
					}
					// for(var k=item.images.length;k<5;k++){
					//   item.images.push('https://rzico.oss-cn-shenzhen.aliyuncs.com/dinnerBar/canyin/canyin-pingfen-gray.png')
					// }
					this.data.shops.push(shopInfo)
				  })
				  this.setData({
					  shops:this.data.shops
          })	
          console.info("this.data.shops--",this.data.shops)		
			})
		},
  }
})
